<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
</head>
<body>
    <div id="app-30">
        <div style="width: 100%; height: 20px; background: #00BFFF;">
            <input type="text" v-model="rName" />
            <hr />
            <router-link :to="{name: rName}">t1</router-link>
            <button type="button" @click="test">首页按钮2</button>
            <router-view></router-view>
        </div>
    </div>

    <script type="text/javascript">
        <!-- vue 的路由旨在为单页面应用开发提供便携 -->
        // 1. 定义链接跳转的模板（组件）
        const t1 = {
            template: `<div style="width: 400px; height: 200px; border: blue 1px solid" >
                    t1
                    </div>`
        };
        const t2 = {
            template: `<div style="width: 400px; height: 200px; border: blue 1px solid" >
                    t2
                    </div>`
        };



        // 2. 定义路由
        const my_router = new VueRouter({
           routes: [
               {
                   path: '/index',
                   name: "r1",
                   component: t1
               },
               {
                   path: '/index2',
                   name: "r2",
                   component: t2
               }
           ]
        });
        // 3. 引用路由
        var vm = new Vue({
           el: '#app-30',
            data: {
              rName: "r1"
            },
            router: my_router,
            methods: {
               test: function () {
                   // js 代码实现路由跳转，编程式导航
                   my_router.push({name: vm.rName});

               }
            }
        });
    </script>

</body>
</html>